~ chicken-core (master) /manual/Module (chicken io)
Trap1[[tags: manual]]2[[toc:]]34== Module (chicken io)56This module provides various Input/Output extensions.78=== read-list910<procedure>(read-list [PORT [READER [MAX]]])</procedure>1112Call {{READER}} up to {{MAX}} times and collect its output in a list. If {{MAX}} is {{#f}}, read until end of file.1314The reader is called with one argument: {{PORT}}.1516{{READER}} defaults to {{read}}, {{MAX}} to {{#f}} and {{PORT}} to {{current-input-port}}, so if you call it with no arguments, it will read all remaining s-expressions from the current input port.171819=== read-buffered2021<procedure>(read-buffered [PORT])</procedure>2223Reads any remaining data buffered after previous read operations on24{{PORT}}. If no remaining data is currently buffered, an empty string25is returned. This procedure will never block. Currently only useful26for string-, process- and tcp ports.2728=== read-byte29=== write-byte3031<procedure>(read-byte [PORT])</procedure><br>32<procedure>(write-byte BYTE [PORT])</procedure>3334Read/write a byte to the port given in {{PORT}}, which default to the values35of {{(current-input-port)}} and {{(current-output-port)}}, respectively.363738=== read-line39=== write-line4041<procedure>(read-line [PORT [LIMIT]])</procedure><br>42<procedure>(write-line STRING [PORT])</procedure>4344Line-input and -output. {{PORT}} defaults to the value of45{{(current-input-port)}} and {{(current-output-port)}},46respectively. If the optional argument {{LIMIT}} is given and47not {{#f}}, then {{read-line}} reads at most {{LIMIT}}48characters per line. {{read-line}} returns a string without the terminating newline and {{write-line}} adds a terminating newline before outputting.495051=== read-lines5253<procedure>(read-lines [PORT [MAX]])</procedure>5455Read {{MAX}} or fewer lines from {{PORT}}. {{MAX}} defaults to56{{most-positive-fixnum}} and {{PORT}} defaults to the value of57{{(current-input-port)}}. Returns a list of strings, each string58representing a line read, not including any line separation59character(s).606162=== read-string63=== read-string!6465<procedure>(read-string [NUM [PORT]])</procedure><br>66<procedure>(read-string! NUM STRING [PORT [START]])</procedure><br>6768Read or write {{NUM}} characters from/to {{PORT}}, which defaults to the69value of {{(current-input-port)}} or {{(current-output-port)}}, respectively.7071If {{NUM}} is {{#f}} or not given, then all data up to the end-of-file is72read, or, in the case of {{write-string}} the whole string is written. If no73more input is available, {{read-string}} returns {{#!eof}}.7475{{read-string!}} reads destructively into the given {{STRING}} argument, but76never more characters than would fit into {{STRING}}. If {{START}} is given,77then the read characters are stored starting at that position.78{{read-string!}} returns the actual number of characters read.798081=== read-bytevector8283<procedure>(read-bytevector [NUM [PORT]])</procedure>8485Read {{NUM}} bytes from {{PORT}}, which defaults to the86value of {{(current-input-port)}}. {{read-bytevector}} allocates87a new buffer and returns it (or the end-of-file object, if at the end88of the input file).8990If {{NUM}} is optional and not given, then all remaining input is read91or the whole bytevector is read/written.9293=== read-bytevector!9495<procedure>(read-bytevector! BYTEVECTOR [PORT START END])</procedure>9697Read bytes from {{PORT}} into {{BYTEVECTOR}}. {{PORT}} defaults to the98value of {{(current-input-port)}} and returns the actual number of bytes read.99100{{START}} and {{END}} designate the range of bytes that should be filled101with input from {{PORT}}. If {{END}} exceeeds the length of {{BYTEVECTOR}}102only as much data is read as fits into the destination buffer.103104=== write-bytevector105106<procedure>(write-bytevector BYTEVECTOR [PORT START END])</procedure>107108Write bytes from {{BYTEVECTOR}} to {{PORT}}. {{PORT}} defaults to the109value of {{(current-output-port)}}.110111{{START}} and {{END}} designate the range of bytes that should be written.112If {{END}} exceeeds the length of {{BYTEVECTOR}}113only as much data is written as is available.114115116=== read-token117118<procedure>(read-token PREDICATE [PORT])</procedure>119120Reads characters from {{PORT}} (which defaults to the value of {{(current-input-port)}})121and calls the procedure {{PREDICATE}} with each character until {{PREDICATE}} returns122false. Returns a string with the accumulated characters.123124---125Previous: [[Module (chicken gc)]]126127Next: [[Module (chicken irregex)]]